<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二分查找</title>
</head>
<body>
    <script>
        //定义一个按顺序排列的数组
        let arr = [1,3,5,8,10,15];
        //目标数
        let num = 3;
        let left = 0;
        let right = arr.length - 1;
        let mid = 0;
        while(left < right){
            mid = Math.floor((left + right) / 2);
            if(arr[mid] > num){
                right = mid - 1;
            }else{
                left = mid + 1;
            }
        }
        console.log(left);
    </script>
</body>
</html>